<?php

$post_id = get_the_ID();
$post_gallery_ids = get_post_meta($post_id, 'theme_gallery', true);
$original_price = get_post_meta($post_id, 'original_price', true);
$theme_short_desc = get_post_meta($post_id, 'theme_short_desc', true);
$theme_version_history = get_post_meta($post_id, 'cao_downurl_new', true);

$file_info = end($theme_version_history);
$filesize = $file_info['filesize'];
$latest_version = $file_info['version'];
$updated_date = $file_info['date'];

$theme_version_reverse = array_reverse($theme_version_history);

$original_or_not = get_post_meta($post_id, 'theme_original', true);

$language_version = get_post_meta($post_id, 'language_type', true);

if($language_version == 'english'){
    $theme_language = '英文版';
}else{
    $theme_language = '中文版';
}

?>

<?php if ( !empty( _cao('single_top_breadcrumb',false) ) ): ?>
    <div class="container-full bg-white">
        <nav class="container d-none d-md-flex py-2" aria-label="breadcrumb">
            <?php zb_the_breadcrumb('breadcrumb mb-0');?>
        </nav>
    </div>
<?php endif;?>

<div class="container mt-2 mt-sm-4 theme-container">

    <div class="row top-content g-2 g-md-3 g-lg-4">
        <div class="col-lg-6 col-md-6 mb-3 pe-0 carousel-container">
            <?php output_content_top_carousel($post_gallery_ids);?>
        </div>
        <div class="col-lg-6 col-md-6 mb-3">
            <div class="card">
                <div class="card-body p-0">
                    <div class="card-title">
                        <?php if($original_or_not){ echo '<span class="badge badge-danger text-danger">原创</span>'; }?><?php the_title('<h1 class="post-title mb-2 mb-lg-3 fw-bold" style="font-size:1.5rem;">', ' '.$latest_version.'</h1>');?>
                    </div>
                    <div class="card-text position-relative">
                        <div class="small text-black-50 pb-1 d-flex gap-2">
                            <?php get_template_part('template-parts/single/entry-meta');?>
                        </div>
                        <div class="btn btn-outline-warning position-absolute top-0 end-0">
                            <a href="/services" style="color:#ff9800;"><i class="fas fa-edit fa-lg"></i> <span class="fw-bolder pl-2">修改定制</span></a>
                        </div>
                        <ul class="list-group list-group-flush mt-3">
                            <li class="text-muted list-group-item bg-white ps-0">
                                <b>版本 : </b> <?php echo $latest_version; ?> 汉化版
                            </li>
                            <li class="text-muted list-group-item bg-white ps-0">
                                <b>文件格式及大小 : </b><span class="mx-2">ZIP格式</span><span><?php echo $filesize; ?>MB</span>
                            </li>
                            <li class="text-muted list-group-item bg-white ps-0 d-flex">
                                <b>下载权限 ：</b>
                                <div class="buy-desc">
                                    <ul class="prices-info d-flex gap-4 pl-2" style="padding-left:1rem;">
                                        <?php
                                        $site_vip_options = get_site_vip_options();
                                        $price_names = [
                                            'default' => __('原价','ripro'),
                                            'no' => $site_vip_options['no']['name'],
                                            'vip' => $site_vip_options['vip']['name'],
                                            'boosvip' => $site_vip_options['boosvip']['name'],
                                        ];
                                        //价格组
                                        $post_price_data = get_post_price_data($post_id);

                                        $default_price = $post_price_data['default'];

                                        foreach ($post_price_data as $type => $coin_price) {
                                            // zb_dump($type,$coin_price);
                                            if ($type=='default') {
                                                continue;
                                            }

                                            if ($coin_price===false) {
                                                $__price_span = '<span>' . __('不可购买','ripro') . '</span>';

                                            }elseif ($coin_price==0) {
                                                $__price_span = '<span>' . __('免费','ripro') . '</span>';

                                            }elseif ($coin_price < $default_price) {
                                                $__rate = $coin_price/$default_price*10;
                                                $__price_span = '<span><i class="fas '.get_site_coin_icon().' me-1"></i>' . $coin_price . get_site_coin_name() . '<sup class="ms-1">' . sprintf(__('%s折','ripro'),$__rate) . '<sup></span>';

                                            }else{
                                                $__price_span = '<span><i class="fas '.get_site_coin_icon().' me-1"></i>' . $coin_price . get_site_coin_name() . '</span>';

                                            }

                                            echo '<li class="price-item '.$type.'">' . $price_names[$type] . ' : ' . $__price_span . '</li>';

                                        }?>
                                    </ul>
                                </div>
                            </li>
                            <li class="text-muted list-group-item bg-white ps-0">
                                <b>简介 ：</b><?php echo $theme_short_desc;?>
                            </li>
                        </ul>

                        <div class="d-flex gap-2">
                            <?php output_download_btn(get_current_user_id(), get_the_ID());?>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row g-2 g-md-3 g-lg-4">

        <div class="content-wrapper col-md-12 col-lg-9" data-sticky-content>
            <div class="card">

                <?php do_action('ripro_ads', 'ad_single_top'); ?>

                <div class="tabs-container">
                    <ul class="d-flex ps-2">
                        <li><a href="#post-content">详细描述</a></li>
                        <li><a href="#version_history">更新历史</a></li>
                    </ul>

                    <div id="post-content">
                        <article <?php post_class('post-content py-3');?> >
                            <?php
                            the_content(
                                sprintf(
                                    wp_kses(
                                        __('继续阅读<span class="screen-reader-text"> "%s"</span>', 'ripro'),
                                        array(
                                            'span' => array(
                                                'class' => array(),
                                            ),
                                        )
                                    ),
                                    wp_kses_post(get_the_title())
                                )
                            );

                            wp_link_pages(
                                array(
                                    'before' => '<div class="custom-nav mb-3"><ul class="pagination d-inline-block d-md-flex justify-content-center"><span class="disabled">' . __('内容分页', 'ripro') . '</span>',
                                    'after'  => '</ul></div>',
                                )
                            );
                            ?>

                            <?php get_template_part('template-parts/single/entry-copyright');?>

                        </article>
                    </div>
                    <div id="version_history">
                        <ol class="timeline">
                            <?php foreach($theme_version_reverse as $v):?>
                                <li><?php echo $v['date'];?> <?php echo $v['version'];?>版本</li>
                            <?php endforeach;?>
                        </ol>
                    </div>
                </div>


                <?php do_action('ripro_ads', 'ad_single_bottum'); ?>

                <?php get_template_part('template-parts/single/entry-tags');?>

                <?php get_template_part('template-parts/single/entry-social');?>

            </div>

            <?php get_template_part('template-parts/single/entry-navigation');?>

            <?php get_template_part('template-parts/single/entry-related-posts');?>

            <?php
            if ( comments_open() || get_comments_number() ) :
                comments_template();
            endif;
            ?>

        </div>

        <div class="sidebar-wrapper col-md-12 col-lg-3 h-100" data-sticky>
            <div class="sidebar">
                <?php dynamic_sidebar( 'single-sidebar' ); ?>
            </div>
        </div>

    </div>
</div>